package com.hg.avaya.util;

import java.util.ArrayList;
import java.util.List;
import javax.naming.NoInitialContextException;

import com.avaya.sce.runtimecommon.IVariableField;
import com.avaya.sce.runtimecommon.SCESession;

import flow.IProjectVariables;

public class SCESessionUtil {

  // 定义一些公共遍变量,在后面的方法中调用
  private static String palyData = IProjectVariables.PLAY_DATA;
  private static String playBeans = IProjectVariables.PLAY_DATA_FIELD_PLAY_BEANS;
  private static String bargeIn = IProjectVariables.PLAY_DATA_FIELD_BARG_IN;
  private static String count = IProjectVariables.COUNT;
  private static String noInputCount = IProjectVariables.COUNT_FIELD_NO_INPUT_COUNT;
  private static String noMatchCount = IProjectVariables.COUNT_FIELD_NO_MATCH_COUNT;

  /**
   * 设置播放话术
   * @param mySession
   * @param prompt
   */
  public static void setTTSPrompt(SCESession mySession, String prompt) {
    List<String[]> list = new ArrayList<String[]>(1);
    list.add(new String[] { prompt, "tts" });
    IVariableField field = mySession.getVariableField(IProjectVariables.PLAY_DATA, playBeans);
    field.setValue(list);
  }

  /**
   * 获取播放话术
   * @param mySession
   * @return
   */
  public static String getTTSPrompt(SCESession mySession) {
    List<String[]> list = getPalyBeans(mySession);
    for (String[] item : list) {
      if (item[1].toLowerCase().equals("tts")) {
        return item[0];
      }
    }
    return "对不起,没有播放话术";
  }

  /**
   * 设置bargein的值
   * @param brageIn
   */
  public static void setBargIn(SCESession mySession, boolean brageIn) {
    IVariableField barginField = mySession.getVariableField(palyData, bargeIn);
    barginField.setValue(brageIn);
  }

  /**
   * 返回 bargein的值
   * @param mySession
   * @return
   */
  public static boolean getBargIn(SCESession mySession) {
    IVariableField barginField = mySession.getVariableField(palyData, bargeIn);
    Boolean brageIn = barginField.getBooleanValue();
    return brageIn;
  }

  /**
   * 返回 playBeans的值
   */
  public static List<String[]> getPalyBeans(SCESession mySession) {
    List<String[]> list = (List<String[]>) mySession.getVariableField(palyData, playBeans)
        .getObjectValue();
    return list;
  }

  /**
   * 返回 NoInputCount的值
   */
  public static int getNoInputCount(SCESession mySession) {
    int intValue = mySession.getVariableField(count, noInputCount).getIntValue();
    return intValue;
  }

  /**
   * 返回noMatchCount的值
   */
  public static int getNoMatchCount(SCESession mySession) {
    int intValue = mySession.getVariableField(count, noMatchCount).getIntValue();
    return intValue;
  }
}